#include "plane.h"

Plane::Plane(const Point &p, const Vector &normal) : p_(p), normal_(normal)
{
    normal_.normalize();
}

Plane::Plane(const Point &p1, const Point &p2, const Point &p3)
{
    Vector v1 = p3 - p1;
    Vector v2 = p2 - p1;

    normal_ = vecprod(v1, v2).normalize();
    p_ = p1;
}

Plane::Plane(const Plane &p) : p_(p.p()), normal_(p.normal())
{
}

Plane& Plane::operator=(const Plane &p)
{
    if( this != &p ) {
        p_ = p.p();
        normal_ = p.normal();
    }

    return *this;
}

const Point& Plane::p() const
{
    return p_;
}

const Vector& Plane::normal() const
{
    return normal_;
}

double Plane::a() const
{
    return normal_(0);
}

double Plane::b() const
{
    return normal_(1);
}

double Plane::c() const
{
    return normal_(2);
}

double Plane::d() const
{
    return -(Vector(p_(0), p_(1), p_(2))*normal_);
}
